<template>
  <div class="login">
    <el-form ref = "AccountForm" :model = "account" :rules = "rules" label-position = "left" label-width = "50px" class = "demo-ruleForm login-container">
      <div>
        <i class="fa fa-home fa-lg"></i>
      </div>
      <div class = "formGroup">
        <el-form-item  label = "账号" prop = "username" >
          <el-input type = "text" v-model="account.username" auto-complete = "off" placeholder = "请输入您的账号" class = "form-control" ></el-input>
        </el-form-item>
        <el-form-item label = "密码" prop = "password" class = "form-inline">
          <el-input type = "password"  v-model="account.password" auto-complete = "off" placeholder = "请输入密码" class = "form-control" ></el-input>
        </el-form-item>
      </div>
      <div class = "remFor">
        <el-checkbox v-model = "checked" class = "remember" >记住密码</el-checkbox>
        <router-link to = "/forgetPass" class = "forgetpwd" >忘记密码？</router-link>
        <router-view></router-view>
      </div>
      <div class = "formButton">
        <el-form-item style = "width:100%;">
          <el-button type="primary" style="width:100%;" @click.native.prevent="login">登 录</el-button>
         <!-- <button style = "width:100%; height: 35px; background: #3A825E; font-size:14px; font-family:PingFang SC; color:#fff; border-radius:2px " @click =  "login" >登录</button> -->
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import mock from '@/mock/index.js';
import Cookies from "js-cookie";
import router from '@/router'
export default {
  name: 'Login',
  data () {
    return {
      logining: false,
      account: {
        username: 'admin',
        password: 'admin',
        captcha: ''
      },
      checked: 'false',
      rules: {
        username: [
          {required: true, message: '请输入账号', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    login () {
      let loginBean = {captcha: 'adsad',password: this.account.password,username: this.account.username}
      this.$api.login.login(loginBean).then((res) => {
        if(res.msg != null) {
          this.$message({
            message: res.msg,
            type: 'error'
          })
        } else {
          Cookies.set('token', res.data.token) // 放置token到Cookie
          sessionStorage.setItem('user', loginBean.username) //保存用户到本地会话
          this.$store.commit('menuRouteLoaded', this.menuRouteLoaded) // 要求重新加载导航菜单
          router.push('/')  // 登录成功，跳转到主页
        }
        this.loading = false
      }).catch((res) => {
        this.$message({
          message: res.message,
          type: 'error'
        })
        }
      )
    }
  },
  computed: {
    ...mapState({
      themeColor: state=>state.app.themeColor,
      menuRouteLoaded: state=>state.app.menuRouteLoaded
    })
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .login-container {

    -webkit-border-radius: 5px;
    border-radius: 15px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 45px 45px 15px 45px;
    background: rgba(255,255,255,0.7)

  ;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;

  }
  label{
    width:70px;
    text-align:left;
  }

  .form-control{
    width:270px;
    flex: 1;
    -webkit-flex: 1;
    -ms-flex: 1;

  }
  .remember{
    width:250px;
    text-align:left;
  }
  .forgetpwd{
    width:500px;
    text-align:right;
    font-size:14px;
    font-family:PingFang SC;
  }
  .remFor{
    margin-bottom: 10px;
    padding-bottom: 10px;
  }
</style>
